package com.slm.krstartimes.utils;

/**
 * Created by lanou3g on 15/8/11.
 */

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;

import com.slm.krstartimes.R;
import com.slm.krstartimes.adapter.AutoCompleteAdapter;


public class AdvancedAutoCompleteTextViewActivity extends RelativeLayout {

    private Context context;
    private AutoCompleteTextView tv;

    public AdvancedAutoCompleteTextViewActivity(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        this.context = context;
    }

    public AdvancedAutoCompleteTextViewActivity(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        this.context = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        initViews();
    }

    /**
     * 初始化
     */
    private void initViews() {
        LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        tv = new AutoCompleteTextView(context);
        tv.setLayoutParams(params);
        tv.setPadding(10, 0, 40, 0);
//      tv.setSingleLine(true);

        LayoutParams p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        p.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        p.addRule(RelativeLayout.CENTER_VERTICAL);
        p.rightMargin = 10;
        ImageView iv = new ImageView(context);
        iv.setLayoutParams(p);
        iv.setScaleType(ScaleType.FIT_CENTER);
        iv.setImageResource(R.mipmap.delete);
        iv.setClickable(true);
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.setText("");
            }
        });

        this.addView(tv);
        this.addView(iv);


    }

    public void setAdapter(AutoCompleteAdapter adapter) {
        tv.setAdapter(adapter);
    }

    public void setThreshold(int threshold) {
        tv.setThreshold(threshold);
    }

    public AutoCompleteTextView getAutoCompleteTextView() {
        return tv;
    }


}